using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Controls;

using FusionWare.SPOT;
using FusionWare.SPOT.Native;

namespace VersionInfoSample
{
    /// <summary>Main Window For the application</summary>
    /// <remarks>
    /// Creates a Text region child element
    /// </remarks>
    public class MainViewWindow : Window
    {
        private Font SmallFont;

        /// <summary> Constructor for the window</summary>
        public MainViewWindow()
        {
            this.SmallFont = Resources.GetFont( Resources.FontResources.small );

            // panel control to fill the window client area
            Panel panel = new Panel();
            panel.HorizontalAlignment = HorizontalAlignment.Stretch;
            panel.VerticalAlignment = VerticalAlignment.Stretch;

            // text flow control to put inside the panel
            TextFlow txtFlow = new TextFlow();
            txtFlow.TextAlignment = TextAlignment.Center;
            txtFlow.HorizontalAlignment = HorizontalAlignment.Center;
            txtFlow.VerticalAlignment = VerticalAlignment.Center;
            
            // add the text runs inside the text flow element
            txtFlow.TextRuns.Add( "Hello World!", this.SmallFont, Colors.Blue );
            txtFlow.TextRuns.Add( TextRun.EndOfLine );
            
            // retrieve and display the version info on the second line
            txtFlow.TextRuns.Add( SystemInfo.Version, this.SmallFont, Colors.Red );
            txtFlow.TextRuns.Add( TextRun.EndOfLine );

            // roll this out the hard way to test and verify each field
            string ver =   "(" + SystemInfo.VersionNumber.Major
                         + "." + SystemInfo.VersionNumber.Minor
                         + "." + SystemInfo.VersionNumber.Build
                         + "." + SystemInfo.VersionNumber.Revision
                         + ")";

            txtFlow.TextRuns.Add( new TextRun( ver, this.SmallFont, Colors.Black ) );

            // VersionInfo numbers can be compared so test against the lowest
            // possible value with SP1
            VersionInfo Sp1EnabledVer = new VersionInfo( 2, 1, 0, 0 );
            if( SystemInfo.VersionNumber < Sp1EnabledVer )
                txtFlow.TextRuns.Add( "[Pre-SP1]", this.SmallFont, Colors.Black );
            else
                txtFlow.TextRuns.Add( "[SP1]", this.SmallFont, Colors.Black );

            // Panel element can have multiple children
            panel.Children.Add( txtFlow );

            // The window has exactly one child
            this.Child = panel;
        }
    }
}
